import pandas as pd
import numpy as np
from sklearn.preprocessing import StandardScaler, MinMaxScaler

# 创建示例 DataFrame
data = {
    'Name': ['Alice', 'Bob', 'Charlie', 'David', 'Eva'],
    'Age': [25, 30, np.nan, 35, 40],
    'Score': [88, np.nan, 85, 79, 90],
    'Date': ['2021-01-01', '2022-02-15', '2023-03-30', '2021-12-01', '2022-05-20']
}
df = pd.DataFrame(data)

# 1. 处理缺失值
# 检测缺失值
print(df.isna())
print('===========检测缺失值示例代码===========')

# 检测非缺失值
print(df.notna())
print('===========检测非缺失值示例代码===========')

# 删除包含缺失值的行
df_no_na = df.dropna(axis=0, how='any')
print(df_no_na)
print('===========删除缺失值示例代码===========')

# 填充缺失值
df_filled = df.fillna({'Age': df['Age'].mean(), 'Score': df['Score'].median()})
print(df_filled)
print('===========填充缺失值示例代码===========')

# 前向填充缺失值
df_ffill = df.ffill()
print(df_ffill)
print('===========前向填充示例代码===========')

# 后向填充缺失值
df_bfill = df.bfill()
print(df_bfill)
print('===========后向填充示例代码===========')

# 插值法填充缺失值
df_interpolated = df.infer_objects(copy=False)
print(df_interpolated)
print('===========插值法填充示例代码===========')